#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

using Weazel.Math;
using Weazel.Gezel.Simulator.Reference.Profiling;

#endregion

namespace Weazel.Gezel.Simulator.Reference
{
    class OutputSignal : AbstractSignal
    {
        private Profiler profiler;
        private Signal signal;

        public OutputSignal(Simulation sim, DatapathContext datapathContext, Symid id, int width, int sign, string name)
            : base(id, name)
        {
            signal = new Signal(sim, datapathContext, id, width, sign, name, false);

            if (sim.profiler != null)
            {
                profiler = sim.profiler;
                profiler.MakeOperation(this, Width());
            }
        }

        internal override void newDefiner(Symid sfgId, AbstractSignal definer)
        {
            signal.newDefiner(sfgId, definer);
        }

        internal override Integer Evaluate(AbstractIpBlock ip, long g)
        {
            Integer value = signal.Evaluate(ip, g);

            if (profiler != null)
                profiler.EvaluateOperation(Id, value);

            return value;
        }

        internal override void Assign(Integer value)
        {
            signal.Assign(value);
        }

        public override bool IsGeneration(long g)
        {
            return signal.IsGeneration(g);
        }

        public override void Show(StringBuilder buffer)
        {
            signal.Show(buffer);
        }

        public override void SetBase(int @base)
        {
            signal.SetBase(@base);
        }

        internal override uint Width()
        {
            return signal.Width();
        }

        internal override uint Signed()
        {
            return signal.Signed();
        }


        internal override void defineDriver(AbstractSignal artsignal)
        {
            signal.defineDriver(artsignal);
        }

        public override bool TraceToSignal(Symid toSignalId, List<AbstractSignal> signals)
        {
            signals.Add(this);
            return signal.TraceToSignal(toSignalId, signals);
        }
    }
}